﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DaoDataEntity;
using MySql.Data.MySqlClient;
using DBAccess;
using LOG;

namespace CacheAccess
{
   public class BackageManager
    {
       private static List<BackageEntity> listback;
       
       public void getList(int playerID)
       {
           listback = CacheManager.m_Backage[playerID];
       }
       public BackageEntity getBackByBackageID(int backageID,int playerID)
       {
           if (listback == null) getList(playerID);
           foreach (BackageEntity b in listback)
           {
               if (b.BackageID == backageID)
                   return b;
           }
           return null;
       }
       public bool addBackage(BackageEntity newBack,int playerID)
       {
           getList( playerID);
           listback.Add(newBack);
           if (CacheManager.m_Backage.ContainsKey(playerID))
               CacheManager.m_Backage[playerID] = listback;
           CacheManager.m_Backage.Add(playerID, listback);
           return true;
       }
       public bool delBackage(int backID, int playerID)
       {
           if (listback == null) getList(playerID);
           foreach (BackageEntity b in listback)
           {
               if (b.BackageID == backID)
               {
                   listback.Remove(b);
                   if (CacheManager.m_Backage.ContainsKey(playerID))
                   {
                       CacheManager.m_Backage[playerID] = listback;
                       return true;
                   }
                   else
                       return false;
               }
           }
           return false;

       }
    }
}
